package com.dulich.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dulich.dto.EventCategoryDTO;
import com.dulich.travelviet.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

public class EventCategoryAdapter extends BaseAdapter{
	private ArrayList<EventCategoryDTO> eventCategoryDTOs;
	private ImageLoader imageLoader;
	private DisplayImageOptions options;
	private Context mContext;
	public EventCategoryAdapter(Context mContext, ArrayList<EventCategoryDTO> eventCategoryDTOs){
		this.mContext = mContext;
		this.eventCategoryDTOs = eventCategoryDTOs;
		setImageLoader();
	}

	@Override
	public int getCount() {
		return eventCategoryDTOs.size();
	}

	@Override
	public Object getItem(int position) {
		return eventCategoryDTOs.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v == null){
			LayoutInflater inflater = LayoutInflater.from(mContext);
			v = inflater.inflate(R.layout.item_event, null);
		}
		TextView nameEventText = (TextView)v.findViewById(R.id.txt_title_event);
		ImageView imageEvent1 = (ImageView)v.findViewById(R.id.img_event_one);
		ImageView imageEvent2 = (ImageView)v.findViewById(R.id.img_event_two);
		ImageView imageEvent3 = (ImageView)v.findViewById(R.id.img_event_three);
		
		nameEventText.setText(eventCategoryDTOs.get(position).getNameEvent());
		imageLoader.displayImage(eventCategoryDTOs.get(position).getUrl1(), imageEvent1, options);
		imageLoader.displayImage(eventCategoryDTOs.get(position).getUrl2(), imageEvent2, options);
		imageLoader.displayImage(eventCategoryDTOs.get(position).getUrl3(), imageEvent3, options);
		return v;
	}
	
	public void setImageLoader(){
		imageLoader = ImageLoader.getInstance();
		imageLoader.init(ImageLoaderConfiguration.createDefault(mContext));
		options = new DisplayImageOptions.Builder().cacheInMemory().cacheOnDisc().build();
	}
}
